<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created:August 14, 2001-->
<!--
$Id: TubeAdd.php,v 1.9 2001/12/06 20:32:57 eugenem Exp eugenem $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/TubeAdd.php,v 1.9 2001/12/06 20:32:57 eugenem Exp eugenem $
$Log: TubeAdd.php,v $
Revision 1.9  2001/12/06 20:32:57  eugenem
Added simple validity checking to focal spot fields.
Fixed problem in query for machine info where mysql_fetch_row() was being used instead of mysql_fetch_array().

Revision 1.8  2001/11/02 19:12:12  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.7  2001/11/02 15:01:03  eugenem
Moved database connect statements to a separate file.

Revision 1.6  2001/09/26 20:19:56  eugenem
Add SELECT box to select MachineID.

Revision 1.5  2001/09/26 20:14:05  eugenem
Got rid of extra check for $HMod (redundant).

Revision 1.4  2001/08/14 20:24:58  eugenem
Changed form action to filename instead of $PHP_SELF

Revision 1.3  2001/08/14 19:53:03  eugenem
Change to execute insertion query only if $HMod is set

Revision 1.2  2001/08/14 19:42:03  eugenem
*** empty log message ***

Revision 1.1  2001/08/14 18:39:12  eugenem
Initial revision

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<?PHP
$machine = mysql_query("select MachineID,Description from Machines where Status=\"Active\" order by Description");
$manuf = mysql_query("select * from Manufacturer");

if (!empty($MachID)) {
  /*
    If this page was called from MachineAdd.php or from itself, then $MachId
    should be set to the machine that was just added.  Now we're
    entering tube information for that machine
  */
  $result = mysql_query("select Description,Model,SerialNumber from Machines where MachineID=$MachID");
  $row = mysql_fetch_array($result);
  $Desc = $row['Description'];
  $Mod = $row['Model'];
  $SN = $row['SerialNumber'];

  /*
    Check for empty or non-numeric values for the focal spots.
    If they are empty or non-numeric, assign 0.0 to focal spot sizes.
    User will have to fix these using the TubeModify.php page.
  */
  if ($LFS == "" || empty($LFS) || !is_numeric($LFS)) $LFS = 0.0;
  if ($MFS == "" || empty($MFS) || !is_numeric($MFS)) $MFS = 0.0;
  if ($SFS == "" || empty($SFS) || !is_numeric($SFS)) $SFS = 0.0;
  if (empty($InstallDate) || $InstallDate=="" || !isset($InstallDate)) $InstallDate = date("Y-m-d");

  $query = "INSERT INTO Tubes 
            (MachineID,HousingModel,HousingSN,InsertModel,InsertSN,ManufDate,LFS,MFS,SFS,Notes,Status,
      HousingManufID,InsertManufID,InstallDate) 
      VALUES ($MachID,\"$HMod\",\"$HSN\",\"$IMod\",\"$ISN\",\"$ManufDate\",$LFS,$MFS,$SFS,
      \"$Notes\",\"Active\",\"$HsgManufID\",\"$InsertManufID\",\"$InstallDate\")";
  $result = mysql_query($query)
    or die ("Insert failed: $query</br>" . mysql_error() . "</br>");

  $TubeID = mysql_insert_id();

  echo "<h2>Tube Added</h2>";
  echo "<p>New tube for $Desc $Mod $SN was added to the database with record number $TubeID </p>";
}
else $MachID=0;
?>

<form action="TubeAdd.php" method="POST">
<p>Machine: <?PHP echo listbox_field($machine,"MachID",$MachID); ?></p>
<p>Housing Manufacturer: <?PHP echo listbox_field($manuf, "HsgManufID",""); mysql_data_seek($manuf,0); ?></p>
<p>Housing Model: <input type="TEXT" name="HMod" size="20"></p>
<p>Housing SN: <input type="TEXT" name="HSN" size="20"></p>
<p>Insert Manufacturer: <?PHP echo listbox_field($manuf,"InsertManufID",""); mysql_data_seek($manuf,0); ?></p>
<p>Insert Model: <input type="TEXT" name="IMod" size="20"></p>
<p>Insert SN: <input type="TEXT" name="ISN" size="20"></p>
<p>Manufacture Date: <input type="TEXT" name="ManufDate" size="10"> (YYYY-MM-DD)</p>
<p>Install date: <input type="text" name="InstallDate" size="10"> (YYYY-MM-DD)</p>
<p>Focal spot size: Large: <input type="TEXT" name="LFS" size="4">mm Medium: <input type="TEXT" name="MFS" size="4">mm Small: <input type="TEXT" name="SFS" size="4">mm</p>
<p><textarea name="Notes" rows="3" cols="70">Additional notes about this tube</textarea></p>
<p><input type="SUBMIT" value="Add tube"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top">Main</a></p>
</form>
<?PHP mysql_close(); ?>
</body>
</html>
